from typing import List
from itertools import cycle
import pprint


class Solution:
    def generateMatrix(self, n: int) -> List[List[int]]:
        arr = [[0] * n for _ in range(n)]

        i = 0
        j = -1

        d = cycle(((0, 1), (1, 0), (0, -1), (-1, 0)))

        # for v in range(1, n * n + 1):
        v = 0
        while v < n * n:
            x_, y_ = next(d)
            print(x_, y_)
            while (
                i + x_ < n
                and j + y_ < n
                and i + x_ >= 0
                and j + y_ >= 0
                and arr[i + x_][j + y_] == 0
            ):
                v += 1
                i += x_
                j += y_
                arr[i][j] = v

        pprint.pprint(arr)
        # if v > 7:
        #     break


if __name__ == "__main__":
    Solution().generateMatrix(1)
